package com.softoa.contorller;

import com.softoa.pojo.*;
import com.softoa.service.IDepartmentService;
import com.softoa.service.IInformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedList;
import java.util.List;

/**
 * @author LinKun
 * @date 2022-6-22 0:16
 */
@RestController
@RequestMapping("/department")
@CrossOrigin
public class DepartmentController {
    @Autowired
    IDepartmentService iDepartmentService;

    @RequestMapping("/list")
    public java.util.List<Department> list() {
        return iDepartmentService.departmentList();
    }

    @RequestMapping("/insert")
    public boolean departmentInsert(Department department) {

        boolean b = iDepartmentService.departmentInsert(department);
        return b;
    }

    @RequestMapping("/update")
    public boolean departmentUpdate(DepartmentParam departmentParam) {
        System.out.println(departmentParam.getDeptId() + "-" + departmentParam.getDeptName() + "-" + departmentParam.getDepPhone());
        boolean b = iDepartmentService.departmentUpdate(departmentParam);
        return b;
    }

    @RequestMapping("/showUsers")
    public java.util.List<User> showUsers(Session session) {
        return iDepartmentService.showUsers(session.getBothSidesId());
    }

    @RequestMapping("/delete")
    public boolean deleteOne(Session session) {
        boolean b = iDepartmentService.deleteOne(session.getBothSidesId());
        System.out.println(session.getBothSidesId() + " id ");
        System.out.println(b);
        return b;
    }

    @RequestMapping("/mutipleDelete")
    public boolean mutipleDelete(int[] ids) {
        boolean b = iDepartmentService.deleteDepts(ids);
        return b;
    }

    @RequestMapping("/search")
    public List<Department> search(WangCai wangCai) {
        List<Department> departments = iDepartmentService.departmentListMultiple(wangCai.getString());
        System.out.println(wangCai.getString());
        for (Department ll : departments) {
            System.out.println(ll.getDeptName());
        }
        return departments;
    }
}
